package models

import "demo/global"
type Article struct {
	ID         int `gorm:"primary_key" json:"id"`
	Title         string `json:"title"`
	Content       string `json:"content"`
}

/* 查找是否存在文章 */
func ExistArticleById(id int) (bool,error) {
	var article Article
	err := global.GormDB.Select("id").Where("id = ? AND deleted_on = ?",id,0).First(&article).Error

	if err != nil {
		return false,err
	}
	if article.ID > 0 {
		return true,nil
	}
	return false,nil
}
/* 获取文章详情 */
func GetArticleDetail(id int) (*Article,error) {
	var article Article
	err := global.GormDB.Select("id").Where("id = ? AND deleted_on = ?",id,0).First(&article).Error

	if err != nil {
		return nil,err
	}
	if article.ID > 0 {
		return &article,nil
	}
	return nil,nil
}